package com.finance3.springmvc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.finance3.springmvc.bean.User;
import com.finance3.springmvc.dao.queryUser;
import com.finance3.springmvc.dao.queryUserImple;

public class queryServlet extends HttpServlet{
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		String id=(String) req.getParameter("uid");
		String password=(String) req.getParameter("upw");
		queryUser queryuser = new queryUserImple();
		User user = queryuser.getUser(id,password);
		req.setAttribute("user", user);
		String missMsg="0";
		if(user==null) {
			//missMsg="密码错误，请重新输入";
			missMsg="1";
			req.setAttribute("missMsg", missMsg);
			
			/*
			 * 不知道为什么就是运行不了
			 * //下面两行是出来修改密码的 resp.setContentType("text/html;utf-8");
			 * resp.getWriter().println(missMsg);
			 */
			
			req.setAttribute("uid", id);
			req.getRequestDispatcher("query.jsp").forward(req, resp);
		}
		else {
			req.getRequestDispatcher("queryResult.jsp").forward(req, resp);
		}
	}
}
